import requestModel from '@/utils/request-model'
import { useModelStore } from '@/stores/model'

// 提交 TAP 任务（多文件 + 方案参数），支持下载进度回调（用于提示）
export const submitTapTask = (data, onDownloadProgress) => {
  const modelStore = useModelStore()
  return requestModel({
    url: modelStore.modelInfo.serverUrl + '/tasks/predict',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data,
    onDownloadProgress
  })
}

// 根据 taskId 轮询任务状态
export const getTapTaskStatus = (taskId) => {
  const modelStore = useModelStore()
  return requestModel({
    url: modelStore.modelInfo.serverUrl + `/tasks/${taskId}`,
    method: 'get'
  })
}

// 下载预测结果（arraybuffer）
export const downloadTapResult = (downloadUrl, headers = { 'Accept': 'application/gzip' }) => {
  const modelStore = useModelStore()
  return requestModel({
    url: modelStore.modelInfo.serverUrl + downloadUrl,
    method: 'get',
    responseType: 'arraybuffer',
    headers
  })
}